<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Rsa;

class BaseController extends Controller
{
    public function success($data, $msg = '')
    {
        $result['httpCode'] = 200;
        $result['message'] = $msg;
        $result['data'] = $data;
        echo json_encode($result);
        die;
    }

    public function error($msg = '', $code = 100)
    {
        $result['httpCode'] = $code;
        $result['message'] = $msg;
        echo json_encode($result);
        die;
    }

    public function emptyError($input,$msg)
    {
        if(is_null($input) || empty($input)) {
            $result['httpCode'] = 100;
            $result['message'] = $msg;
            echo json_encode($result);
            die;
        }
    }

    public function ToolongError($input,$msg,$long=10)
    {
        if(mb_strlen($input)>$long) {
            $this->error($msg);
        }
    }

    public function MobileError($mobile)
    {
        if(!preg_match("/^1[345789]\d{9}$/",$mobile)) {
            $this->error('手机号格式错误');
        }
    }

}